package dao;


import entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;

public class UserDao implements UserDaoInterface{
    private UserDao(){}
    private static UserDao userDao ;
    public static UserDao getInstance(){
        if(userDao == null){
            userDao = new UserDao();
        }
        return userDao;
    }

    @Override
    public void login(Connection connection, User user) throws SQLException {
        String sql_login="SELECT * FROM user WHERE username=? AND password=?";
        PreparedStatement preparedStatement=connection.prepareStatement(sql_login);
        preparedStatement.setString(1,user.getUsername());
        preparedStatement.setString(2,user.getPassword());
        ResultSet resultSet=preparedStatement.executeQuery();
        if(resultSet.next()){
            Long id=resultSet.getLong("id");
            user.setId(id);
        }
    }
}
